package com.example.mysavingkeyvalue;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MySavingKeyValue extends Activity {
	public EditText et_value;
	public Button btn_save;
	public String save_value;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_saving_key_value);
		setView();
	}
	
	private void setView(){
		et_value = (EditText)findViewById(R.id.et_value);
		btn_save = (Button)findViewById(R.id.btn_save);
		
		save_value = read_share_key("truedano");
		et_value.setText(save_value);
		
		btn_save.setOnClickListener(new Button.OnClickListener(){

			@Override
			public void onClick(View v) {
				write_share_key("truedano", et_value.getText().toString());
			}
			
		});
	}
	
	public void write_share_key(String key, String value){
		SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPref.edit();
		editor.putString(key, value);
		editor.commit();
	}
	
	public String read_share_key(String key){
		SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
		return sharedPref.getString(key, null);
	}
}
